import { App } from 'vue';
import { AppRouter } from '@ibiz-template/vue3-components';
import IBizCommon from './common';
import IBizControl from './control';
import IBizEditor from './editor';
import IBizPanelComponent from './panel-component';
import { CustomOpenViewUtil, CustomOverlayController, JSUtil } from './util';
import { DefaultErrorHandler } from './utils';
import { IBizViewEngine } from './view-engine';
import { IBizUiAction } from './ui-action';

JSUtil.loadJS();

export default {
  install(app: App): void {
    app.use(IBizCommon);
    app.use(IBizEditor);
    app.use(IBizControl);
    app.use(IBizPanelComponent);
    app.use(IBizViewEngine);
    app.use(IBizUiAction);
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    if (!(window as any).qiaoyiCustomPlugins) {
      ibiz.openView = new CustomOpenViewUtil(AppRouter.getRouter());
      ibiz.overlay = new CustomOverlayController();
      ibiz.util.error.register(new DefaultErrorHandler());
      (window as any).qiaoyiCustomPlugins = true;
    }
  },
};
